 
@echo off
SetLocal EnableDelayedExpansion

 
call config.bat
 
echo.
echo -------------------------------------
echo  NISSAN DCM release
echo -------------------------------------
echo.
echo [1] Release for DCM "NISSAN_INFINITI_NAM"
echo [2] Release for DCM "NISSAN_DFL"
echo [3] Release for DCM "NISSAN_L42L"
echo [4] Release for DCM "NISSAN_NCIC"
echo [5] Release for DCM "NISSAN_TEST"
echo [0] Exit
 
:REL_SELECTION
set /P select="selection:"
 
if %select%==1  goto REL_INFINITI
if %select%==2  goto REL_DFL
if %select%==3  goto REL_L42L
if %select%==4  goto REL_NCIC
if %select%==5  goto REL_TEST
if %select%==0  goto END
 
echo Invalid selection, please try again
goto REL_SELECTION
 
 
 
REM -------SET VIEW_HOME_PATH-----------------------------------------------------------------------------------------------------------------------------
REM /*{{{*/
:REL_INFINITI
set DCM_TYPE='INFINITI'
set VIEW_HOME_PATH=%INFINITI_VIEW_HOME_PATH%
goto REL_START
 
:REL_L42L
set DCM_TYPE='L42L'
set VIEW_HOME_PATH=%L42L_VIEW_HOME_PATH%
goto REL_START
 
:REL_DFL
set DCM_TYPE='DFL'
set VIEW_HOME_PATH=%DFL_VIEW_HOME_PATH%
goto REL_START
 
:REL_NCIC
set DCM_TYPE='NCIC'
set VIEW_HOME_PATH=%NCIC_VIEW_HOME_PATH%
goto REL_START
 
:REL_TEST
set DCM_TYPE='INFINITI'
set VIEW_HOME_PATH=%TEST_VIEW_HOME_PATH%
goto REL_START
REM /*}}}*/ 

REM -------RELESE START at here---------------------------------------------------------------------------------------------------------------------------
:REL_START
if %ACTION_RELEASE%=='YES'  (
REM action is release, all step should be done
    set ACTION_UPDATE_VIEW='YES'
    set ACTION_GENERATE_SGOLD_CODE='YES'
    set ACTION_UPDATE_SGOLD_VER='YES'
    set ACTION_UPDATE_S12_VER='YES'
    set ACTION_BUILD_SGOLD_IMAGE='YES'
    set ACTION_LABEL='YES'
)

REM =======Update code in view=============================================
REM /*{{{*/
:UPDATE_CODE
if %ACTION_UPDATE_VIEW%=='YES' (
        echo --------Update Code--------
        REM first update the code in this view
        cleartool update %VIEW_HOME_PATH%
) 
REM /*}}}*/

REM =======Generate SGOLD code=============================================
REM /*{{{*/
:GEN_SGOLD_CODE
if %ACTION_GENERATE_SGOLD_CODE%=='YES' (
        echo --------Generate SGOLD code--------
        set project= %VIEW_HOME_PATH%\%PROJECT_PATH%\%PROJECT_NAME%
        REM delete targe dir
        del /Q %VIEW_HOME_PATH%\%PROJECT_PATH%\Svt\Target 
        RhapsodyCL -cmd=open !project! -cmd=generate
)
REM  /*}}}*/

REM =======Modify Sgold versio file========================================
REM /*{{{*/
:UPDATE_SGOLD_VERSION
if %ACTION_UPDATE_SGOLD_VER%=='YES' (
        echo --------Update Sgold version file--------
        set sgold_version_file=%VIEW_HOME_PATH%\%SGOLD_VERSION_FILE%
        REM check out the file
        cleartool co -nc !sgold_version_file!
        REM modify version section
        set command="let ver_high=%SGOLD_VER_HIGH% | let ver_low=%SGOLD_VER_LOW% | let release_type=%SGOLD_REL_TYPE% | let sw_date=%SGOLD_SW_DATE% | let model_year=%SGOLD_MODEL_YEAR%"
        gvim -c !command! -s Sgold_changeversion.vim !sgold_version_file!
        REM check in the file
        cleartool ci -nc !sgold_version_file!

        REM need change  also need change SVN section

        )
REM /*}}}*/

REM =======Modify S12 versio file==========================================
REM /*{{{*/
:UPDATE_S12_VERSION
if %ACTION_UPDATE_S12_VER%=='YES' (
        echo --------Update S12 version file--------
        set s12_version_file=%VIEW_HOME_PATH%\%S12_VERSION_FILE%
        REM check out the file
        cleartool co -nc !s12_version_file!
        REM modify version section
        set command="let dcm_type=%DCM_TYPE% | let version_id=%S12_VERSION_ID% | let sgold_ver_high=%SGOLD_VER_HIGH_HEX% | let sgold_ver_low=%SGOLD_VER_LOW_HEX%" 
        gvim -c !command! !s12_version_file! -S %RELEASE_SCRIPT_PATH%\S12_change_version.vim
        REM check in the file
        cleartool ci -nc -ide !s12_version_file!
        )
REM  /*}}}*/

REM =======Build Sgold image===============================================
REM /*{{{*/
:BUILD_SGOLD_IMAGE
if %ACTION_BUILD_SGOLD_IMAGE%=='YES' (
        echo ---------Build Sgold image--------

        cd %VIEW_HOME_PATH%\%NOVANTO_CODE_DIR_PATH%\
        set clean_file=clean_script.bat
        set build_file=build_script.bat

        if EXIST !clean_file! del !clean_file!
        if exist !build_file! del !build_file!

        copy clean_all.bat !clean_file!
        copy build.bat !build_file! 
        gvim !clean_file! -S %RELEASE_SCRIPT_PATH%\clean_script_change.vim 
        gvim !build_file! -S %RELEASE_SCRIPT_PATH%\build_script_change.vim 

        REM first clean all file
        cd %VIEW_HOME_PATH%\%NOVANTO_CODE_DIR_PATH%\
        call !clean_file!

        REM then build the image
        cd %VIEW_HOME_PATH%\%NOVANTO_CODE_DIR_PATH%\
        call !build_file! %DCM_TYPE%

        REM ********move the build image to release folder********
        cd %VIEW_HOME_PATH%
        set build_dir=Novanto\code\native\casnad_system\system-build\HW\MPE
        if %DCM_TYPE%=='INFINITI' (
                set release_dir=Nissan_DCM\Infiniti_DCM\releases\%RELEASE_DIR_NAME%\%RELEASE_SUB_DIR_NAME%
                ) else (
                set release_dir=Nissan_DCM\release\%RELEASE_DIR_NAME%\%RELEASE_SUB_DIR_NAME%
                )
        
        mkdir .\!release_dir!\build\sgold

        if exist .\!build_dir!\CAS_NAD2.fls ( 
                copy .\!build_dir!\builderr.txt .\!release_dir!\build\sgold\builderr.txt
                copy .\!build_dir!\CAS_NAD2.axf .\!release_dir!\build\sgold\%RELEASE_SUB_DIR_NAME%.axf
                copy .\!build_dir!\CAS_NAD2.eep .\!release_dir!\build\sgold\%RELEASE_SUB_DIR_NAME%.eep
                copy .\!build_dir!\CAS_NAD2.fls .\!release_dir!\build\sgold\%RELEASE_SUB_DIR_NAME%.fls
                copy .\!build_dir!\CAS_NAD2.map .\!release_dir!\build\sgold\CAS_NAD2.map
                copy .\!build_dir!\CAS_NAD2.txt .\!release_dir!\build\sgold\CAS_NAD2.txt
                copy .\!build_dir!\CAS_NAD2\BOOT_VECT .\!release_dir!\build\sgold\BOOT_VECT
                copy .\!build_dir!\CAS_NAD2\CAS_NAD2.hex .\!release_dir!\build\sgold\%RELEASE_SUB_DIR_NAME%.hex
                copy .\!build_dir!\CAS_NAD2\EE_STATIC .\!release_dir!\build\sgold\EE_STATIC
                copy .\!build_dir!\CAS_NAD2\EE_STATIC_proc .\!release_dir!\build\sgold\EE_STATIC_proc
                )

        )
REM /*}}}*/

REM =======Add label to the release========================================
REM /*{{{*/
:ADD_LABEL
if %ACTION_LABEL%=='YES' (
        echo --------Add label--------
        REM create label for VOB
        cleartool mklbtype -nc %NOVANTO_RELEASE_LABEL_TYPE_NAME%@\Novanto
        cleartool mklbtype -nc %GM_VLBS_RELEASE_LABEL_TYPE_NAME%@\GM_VLBS
        cleartool mklbtype -nc %NISSAN_DCM_RELEASE_LABEL_TYPE_NAME%@\Nissan_DCM
        REM attach label
        cleartool mklabel -recurse %NOVANTO_RELEASE_LABEL_TYPE_NAME% %VIEW_HOME_PATH%\Novanto
        cleartool mklabel -recurse %GM_VLBS_RELEASE_LABEL_TYPE_NAME% %VIEW_HOME_PATH%\GM_VLBS
        cleartool mklabel -recurse %NISSAN_DCM_RELEASE_LABEL_TYPE_NAME% %VIEW_HOME_PATH%\Nissan_DCM
)
REM /*}}}*/





goto END
 
 
 
:ERROR
echo this is an error!!!!
 
:END
pause
